package com.smart.controller;


import com.smart.entity.Result;
import com.smart.entity.ViolationRecords;
import com.smart.service.IViolationRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 记录违规情况的表 前端控制器
 * </p>
 *
 * @author Cookies
 * @since 2024-05-13
 */
@RestController
@CrossOrigin
@RequestMapping("/violation-records")
@Api(tags = "违规记录相关接口")
public class ViolationRecordsController {
    @Autowired
    private IViolationRecordsService violationRecordsService;

    @GetMapping("/{current}/{size}")
    @ApiOperation(value = "获取违规记录", response = Result.class)
    public Result getEmployeeList(
        @PathVariable @ApiParam(name = "当前页", required = true) Integer current,
        @PathVariable @ApiParam(name = "每页数量", required = true) Integer size,
        @RequestParam(required = false) @ApiParam(name = "违规者Uid") String violatorUid) {
        return Result.success(violationRecordsService.getViolationRecordsList(current, size, violatorUid));
    }

    @PostMapping
    @ApiOperation(value = "添加违规记录", response = Result.class)
    public Result addViolationRecords(
        @RequestBody @ApiParam(name = "违规记录信息", required = true) ViolationRecords violationRecords) {
        boolean isSucceed = violationRecordsService.save(violationRecords);
        return isSucceed ? Result.success() : Result.error("操作失败");
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "修改指定违规记录状态", response = Result.class)
    public Result updateViolationRecords(
            @PathVariable @ApiParam(name = "违规记录ID", required = true) Integer id,
            @RequestBody @ApiParam(name = "违规记录信息 0-未处理 1-已处理", required = true)  Integer status) {
        ViolationRecords violationRecords = new ViolationRecords();
        violationRecords.setId(id);
        violationRecords.setStatus(status);
        boolean isSucceed = violationRecordsService.updateById(violationRecords);
        return isSucceed ? Result.success() : Result.error("操作失败");
    }
}
